package com.shengqin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shengqin.entity.UserRelSchool;
import com.shengqin.mapper.UserRelSchoolMapper;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Set;

@Service
public class UserRelSchoolService extends ServiceImpl<UserRelSchoolMapper, UserRelSchool> {

    public List<UserRelSchool> listByUserId(Integer userId) {
        QueryWrapper<UserRelSchool> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserRelSchool::getUserId, userId);
        return  list(wrapper);
    }

    public void removeBySchoolId(Integer schoolId) {
        QueryWrapper<UserRelSchool> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserRelSchool::getSchoolId, schoolId);
        remove(wrapper);
    }

    public List<UserRelSchool> listByUserIds(Set<Integer> userIds) {
        QueryWrapper<UserRelSchool> wrapper = new QueryWrapper<>();
        wrapper.lambda().in(UserRelSchool::getUserId, userIds);
        List<UserRelSchool> userRelSchools = list(wrapper);
        return userRelSchools;
    }

    public void removeByUserIdsAndSchoolId(Set<Long> userIdList, Integer schoolId) {
        QueryWrapper<UserRelSchool> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserRelSchool::getSchoolId, schoolId);
        wrapper.lambda().in(UserRelSchool::getUserId, userIdList);
        remove(wrapper);
    }

    public void updateSchoolName(Integer schoolId, String name) {
        UpdateWrapper<UserRelSchool> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(UserRelSchool::getSchoolId, schoolId);
        updateWrapper.lambda().set(UserRelSchool::getSchoolName, name);
        update(updateWrapper);
    }
}
